
/**
 * Namespace    Classes.Entities
 * Class        Address
 * Author       Bram Vandenbussche
 * Description  Provides object logic for an adress
 * Version      1.0
**/

Address = function() {
    this.ID = 0;
    this.CustomerID = 0;
    this.CountryID = 3;
    this.Alias = '';
    
    this.Company = '';
    this.Lastname = '';
    this.Firstname = '';
    this.Address1 = '';
    this.Address2 = '';
    this.Postcode = '';
    this.City = '';
    this.Phone = '';
    this.MobilePhone = '';
    this.VAT = '';
    
    this.DateAdded = '';
    this.DateUpdated = '';
}

Address.prototype.Serialize = function() {
	var str = '';

    str += '<address>';
    
    str += '<id>' + this.ID + '</id>';
    str += '<customer_id>' + this.CustomerID + '</customer_id>';
    str += '<country_id>' + this.CountryID + '</country_id>';
    str += '<alias>' + this.Alias + '</alias>';    
    
    str += '<firstname>' + this.Firstname + '</firstname>';    
    str += '<lastname>' + this.Lastname + '</lastname>';
    
    str += '<address1>' + this.Address1 + '</address1>';
    str += '<address2>' + this.Address2 + '</address2>';
	str += '<postcode>' + this.Postcode + '</postcode>';
    str += '<city>' + this.City + '</city>';
    str += '<vat>' + this.VAT + '</vat>';
    
    str += '<phone>' + this.Phone + '</phone>';
	str += '<mobile_phone>' + this.MobilePhone + '</mobile_phone>';
    
	str += '<date_add>' + this.DateAdded + '</date_add>';
	str += '<date_upd>' + this.DateUpdated + '</date_upd>';
	
	str += '</address>';
	
	return str;
}


Address.prototype.Deserialize = function(xml) {
	this.ID = $("id", xml).html();
    this.CustomerID = $("customer_id", xml).html();
    this.CountryID = $("country_id", xml).html();
    this.Alias = $("alias", xml).html();
    
    this.Firstname = $("firstname", xml).html();
    this.Lastname = $("lastname", xml).html();
    
    this.Address1 = $("address1", xml).html();
    this.Address2 = $("address2", xml).html();
	this.Postcode = $("postcode", xml).html();
    this.City = $("city", xml).html();
    this.VAT = $("vat", xml).html();
    
    this.Phone = $("phone", xml).html();
    this.MobilePhone = $("mobile_phone", xml).html();
    
	this.DateAdded = $("date_add", xml).html();
	this.DateUpdated = $("date_upd", xml).html();
}


Address.prototype.AssembleFromJson = function(json) {
	this.ID = json.id;
    this.CustomerID = json.id_customer
    this.CountryID = json.id_country;
    this.Alias = json.alias;
    
	this.Firstname = json.firstname;
	this.Lastname = json.lastname;    
    this.Address1 = json.address1;	
	this.Address2 = json.address2;
	this.Postcode = json.postcode;
    this.City = json.city;
    this.VAT = json.vat_number;
    
    this.Phone = json.phone;
    this.MobilePhone = json.phone_mobile;
    
	this.DateAdded = json.date_add;
	this.DateUpdated = json.date_upd;
}


Address.prototype.Name = function() {
	return this.Firstname + ' ' + this.Lastname;
}